﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <script type="text/javascript" src="../../Content/highlighter/scripts/shCore.js"></script>
    <script type="text/javascript" src="../../Content/highlighter/scripts/shBrushCSharp.js"></script>
    <script type="text/javascript" src="../../Content/highlighter/scripts/shBrushXml.js"></script>
    <link type="text/css" rel="stylesheet" href="../../Content/highlighter/styles/shCoreDefault.css" />
    <script type="text/javascript">SyntaxHighlighter.all();</script>
</head>
<body>
    <h3>高并发下Session引起的锁问题</h3>
    <p>
        使用非并发锁：
        MemcachedSessionProvider nuget安装
        https://github.com/rohita/MemcachedSessionProvider
        定义配置类型节：
        <pre class="brush:xml">
            &lt;sectionGroup name="sessionManagement">
                &lt;section name="memcached" type="Enyim.Caching.Configuration.MemcachedClientSection, Enyim.Caching" />
            &lt;/sectionGroup>
        </pre>
        定义配置：必须紧跟配置节(configSections)后
        <pre class="brush:xml">
            &lt;sessionManagement>
            &lt;memcached protocol="Binary">
                &lt;servers>
                    &lt;!-- make sure you use the same ordering of nodes in every configuration you have -->
                    &lt;add address="192.168.6.2" port="11211" />
                &lt;/servers>
                &lt;locator type="MemcachedSessionProvider.SessionNodeLocator, MemcachedSessionProvider" />
            &lt;/memcached>
        &lt;/sessionManagement>
        </pre>
        替换原有Session Provider:
        <pre class="brush:xml">
            &lt;--替换-->
            &lt;sessionState cookieless="false" mode="Custom" customProvider="Memcached">
                &lt;providers>
                    &lt;add name="Memcached" type="MemcachedSessionProvider.SessionProvider, MemcachedSessionProvider" />
                &lt;/providers>
            &lt;/sessionState>
        </pre>
    </p>
</body>
</html>